package com.lvchuang.mapper;

import com.lvchuang.model.News;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NewsMapper {
    @Select("select * from news LEFT JOIN news_category ON news.category_id=news_category.category_id")
    List<News> selectAll();

    @Select("select * from news where id=#{id}")
    News selectById(int id);

    @Insert("insert into news (id, title, reporter, release_time, update_time, content, key_words, category_id) values (#{id}, #{title}, #{reporter},#{release_time}, #{update_time}, #{content},#{key_words}, #{category_id})")
    void insertNews(News news);

    @Delete("delete from news where id = #{id}")
    void deleteNews(Integer id);

    @Update("update news  set title = #{title},reporter = #{reporter},release_time = #{release_time},update_time = #{update_time},content = #{content},key_words = #{key_words},category_id = #{category_id} where id = #{id}")
    void updateNewsByNews(News news);
}
